package wsh;

import java.awt.Color;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

import javax.swing.JFrame;

import javax.swing.JLabel;

public class zhuce{
	public zhuce(String login,String password) throws ClassNotFoundException, SQLException{
		//默认输入的是字符串，所以建议测试的时候输入字符串

			System.out.println("用户名：");
			Scanner scanner = new Scanner(System.in);
			//获取用户名
			String userID = login;
			System.out.println("密码:");
			Scanner scanner2 = new Scanner(System.in);
			//获取密码
			String psw1 = password;
			//先检查用户名是否存在，若不存在则继续注册
			String sql2 = "select * from test where 用户名 ="+"'"+userID+"'";
			DBHelper DBquery = new DBHelper();
			ResultSet rsSet =  DBquery.DB(sql2);
			if (rsSet.next()) {
				System.out.println("该用户名已被注册,请更换您的用户名再进行注册");
				DBquery.downConn();
				}
			else{
				String sql = "insert into test(用户名,密码,胜场) values ("+userID+","+psw1+","+0+")";
				DBHelper DBupdate = new DBHelper();
				DBupdate.excuteSql(sql);
				System.out.println("恭喜您注册成功");

		        JFrame f = new JFrame("");
		        f.setSize(200, 150);
		        f.setLocationRelativeTo(null);
		        f.setLayout(null);
		        JLabel l = new JLabel("恭喜您注册成功");
		        //文字颜色
		        l.setForeground(Color.red);
		        l.setBounds(50, 50, 280, 30);

		        f.add(l);

		        f.setVisible(true);
				//关闭connection的连接哦，防止泄露
				DBupdate.downConn();
				scanner.close();
				scanner2.close();
			}
		}
	
}
	

	
